home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
TEMP
/
GNU
/
bison
/
RpcalcDecm
< prev
next >
Wrap
Text File
|
1995-06-28
|
2KB
|
46 lines
Rpcalc Decls
Previous: <RPN Calc=>RPNCalc> * Next: <Rpcalc Rules=>RpcalcRulf> * Up: <RPN Calc=>RPNCalc>
#Wrap on
{fH4}Declarations for {fCode}rpcalc{f}{f}
Here are the C and Bison declarations for the reverse polish notation
calculator. As in C, comments are placed between {fEmphasis}\/\*…\*\/{f}.
#Wrap off
#fCode
\/\* Reverse polish notation calculator. \*\/
%\{
\#define YYSTYPE double
\#include <math.h>
%\}
%token NUM
%% \/\* Grammar rules and actions follow \*\/
#f
#Wrap on
The C declarations section (\*Note <C Declarations=>CDeclarati>: The C Declarations Section) contains two
preprocessor directives.
The {fCode}\#define{f} directive defines the macro {fCode}YYSTYPE{f}, thus
specifying the C data type for semantic values of both tokens and groupings
(\*Note <Value Type=>ValueType>: Data Types of Semantic Values). The Bison parser will use whatever type
{fCode}YYSTYPE{f} is defined as; if you don't define it, {fCode}int{f} is the
default. Because we specify {fCode}double{f}, each token and each expression
has an associated value, which is a floating point number.
The {fCode}\#include{f} directive is used to declare the exponentiation
function {fCode}pow{f}.
The second section, Bison declarations, provides information to Bison about
the token types (\*Note <Bison Declarations=>BisonDecla>: The Bison Declarations Section). Each terminal symbol that is
not a single-character literal must be declared here. (Single-character
literals normally don't need to be declared.) In this example, all the
arithmetic operators are designated by single-character literals, so the
only terminal symbol that needs to be declared is {fCode}NUM{f}, the token
type for numeric constants.